
module Fastlane
  module Actions
    module SharedValues
      REMOVE_TAG_CUSTOM_VALUE = :REMOVE_TAG_CUSTOM_VALUE
    end

    class RemoveTagAction < Action
        
        # action 真正的执行逻辑
      def self.run(params)
      
      # 1. action 名称
      # 2. 功能：可以删除本地和远程的标签
      # 3.remove_tag(tagName:0.1.0, rL:true, rR:true)
      #  remove_tag(tagName:0.1.0) rL rR 默认都是True
      tagName = params[:tagName]
      rL = params[:rL]
      rR = params[:rR]
      
      # 1.拼接需要执行的命令
      # 1.1 定义一个数组
      cmds = []
      if rL
      cmds << "git tag -d #{tagName}"
      end
    
      if rR
      cmds << "git push origin :#{tagName}"
      end
      
      UI.message("发现了#{tagName}标签已经存在, 此时, 即将执行删除动作 🎯.")

      resultCmd = cmds.join(" & ")
      Action.sh(resultCmd)
      end

      #####################################################
      # @!group Documentation
      #####################################################

# action 的功能描述
      def self.description
        "删除本地和远程标签"
      end

# action 具体功能描述
      def self.details
        "remove_tag(tagName:0.1.0, rL:true, rR:true) remove_tag(tagName:0.1.0) 删除本地和远程标签"
      end

# 参数
      def self.available_options
        # Define all options your action supports. 
        
        # Below a few examples
        [
          FastlaneCore::ConfigItem.new(key: :tagName,
                                       description: "需要被删除的标签名称",
                                       is_string:true,
                                       optional:false),
          FastlaneCore::ConfigItem.new(key: :rL,
                             description: "是否删除本地的标签",
                             is_string:false,
                             optional:true,
                            default_value:true),
          FastlaneCore::ConfigItem.new(key: :rR,
                             description: "是否删除远程的标签",
                             is_string:false,
                             optional:true,
                            default_value:true),
        ]
      end

# 输出
      def self.output
        ""
      end

# 返回值
      def self.return_value
        nil
      end

      def self.authors
        # So no one will ever forget your contribution to fastlane :) You are awesome btw!
        ["appbanana/1234@qq.com"]
      end

      def self.is_supported?(platform)
        # you can do things like
        # 
        #  true
        # 
        #  platform == :ios
        # 
        #  [:ios, :mac].include?(platform)
        # 

        platform == :ios
      end
    end
  end
end
